<template>
  <j-modal
    :confirmLoading="confirmLoading"
    :maskClosable="false"
    :title="title"
    :visible="visible"
    :width="1200"
    switchFullscreen
    @cancel="handleCancel"
    @ok="handleOk"
  >
    <a-spin :spinning="confirmLoading">
      <a-form :form="form">
        <a-row>
          <a-col :sm="12" :xs="24">
            <a-form-item :labelCol="labelCol" :wrapperCol="wrapperCol" label="库房名称">
              <a-input
                v-decorator="['name', { rules: [{ required: true, message: '请输入库房名称' }] }]"
                placeholder="请输入库房名称"
              />
            </a-form-item>
          </a-col>
          <a-col :sm="12" :xs="24">
            <a-form-item :labelCol="labelCol" :wrapperCol="wrapperCol" label="仓库管理员">
              <a-select v-decorator="['managerId', { rules: [{ required: true, message: '请选择仓库管理员' }] }]"
                        placeholder="请选择仓库管理员" @change="">
                <a-select-option v-for="(d, index) in storekeeperList" :key="index" :value="d.id">
                  {{ d.name }}
                </a-select-option>
              </a-select>
            </a-form-item>
          </a-col>
        </a-row>
      </a-form>
    </a-spin>
  </j-modal>
</template>

<script>
import { getAction, httpAction } from '@/api/manage'

export default {
  name: 'AddStorage',
  data() {
    return {
      title: '车辆颜色设置',
      visible: false,
      model: {},
      managerId: '',
      storekeeperList: [],
      saleSource: [],
      SaleInfosLike: [],
      labelCol: {
        xs: { span: 24 },
        sm: { span: 5 }
      },
      wrapperCol: {
        xs: { span: 24 },
        sm: { span: 16 }
      },

      confirmLoading: false,
      form: this.$form.createForm(this),
      validatorRules: {},
      url: {
        add: '/sale/cxmSaleStoreInfo/addStoreInfo',
        edit: '/sale/cxmSaleStoreInfo/editStoreInfo'
      },
      showDing: false,
      showEnterpriseUscc: false
    }
  },
  created() {
  },
  methods: {
    changeDepositNotes(val) {
      if (val == '不可退') {
        this.showDing = true
      } else {
        this.showDing = false
      }
    },
    add() {
      const that = this
      that.edit({})
    },
    edit(record) {
      console.log(record)
      getAction('/sale/cxmSaleStaffInfo/queryStaffMap').then((res) => {
        console.log(res)
        if (res.success) {
          let storekeeperList = []
          for (const key in res.result) {
            storekeeperList.push({ 'id': key, 'name': res.result[key] })
          }
          this.storekeeperList = storekeeperList
        }
      })
      this.form.resetFields()
      this.model = Object.assign({}, record)
      console.log(this.model)
      this.visible = true
      this.$nextTick(() => {
        this.form.setFieldsValue({
          name: this.model.name,
          managerId: this.model.managerId,
        })
      })

    },
    close() {
      this.$emit('close')
      this.visible = false
    },
    handleOk() {
      const that = this
      // 触发表单验证
      this.form.validateFields((err, values) => {
        if (!err) {
          that.confirmLoading = true
          let httpurl = ''
          let method = ''
          if (!this.model.id) {
            httpurl += this.url.add
            method = 'post'
          } else {
            httpurl += this.url.edit
            method = 'post'
          }
          let formData = Object.assign(this.model, values)
          //时间格式化
          /* formData.createTime = formData.createTime ? formData.createTime.format('YYYY-MM-DD HH:mm:ss') : null */

          httpAction(httpurl, formData, method)
            .then((res) => {
              if (res.success) {
                that.$message.success(res.message)
                that.$emit('ok')
              } else {
                that.$message.warning(res.message)
              }
            })
            .finally(() => {
              that.confirmLoading = false
              that.close()
            })
        }
      })
    },
    handleCancel() {
      this.close()
    }
  }
}
</script>

<style lang="less" scoped>
</style>